import { Injectable } from '@angular/core';
import { ApolloQueryResult, FetchResult } from '@apollo/client/core';
import { Apollo, gql, QueryRef } from 'apollo-angular';
import { Observable } from 'rxjs';
import { AccountManagerServiceApi,
AccountManagerService_listResult,
AccountManagerService_listVariables,
AccountManagerService_totalCountResult,
AccountManagerService_searchResult,
AccountManagerService_searchVariables,
AccountManagerService_loadAllResult,
AccountManagerService_getByIdResult,
AccountManagerService_getByIdVariables,
AccountManagerService_modifyPasswordResult,
AccountManagerService_modifyPasswordVariables,
AccountManagerService_saveResult,
AccountManagerService_saveVariables,
AccountManagerService_removeByIdResult,
AccountManagerService_removeByIdVariables,
AccountManagerService_removeByIdListResult,
AccountManagerService_removeByIdListVariables,
AccountResultInfo, AccountPageInfo,
AccountConnection,
AccountPackage,
AccountOrderBy,
AccountMutationInfo,
AccountStringFilter,
AccountNumberFilter,
AccountBooleanFilter,
accountManagerServiceQuery,
accountManagerServiceMutation,
AccountManagerServiceQueryOptions,
AccountStore,
AccountView,
AccountInput,
AccountFilter,
AccountErrorBody} from '../model/account_manager_service.model';

/************************************************************************
 * 账户管理
 */
@Injectable({
    providedIn: 'root'
})
export class AccountManagerService implements AccountManagerServiceApi {

        private listGql:string;
        private totalCountGql:string;
        private searchGql:string;
        private searchObjectRef: QueryRef<AccountManagerService_searchResult>;
        private loadAllGql:string;
        private getByIdGql:string;

    constructor(private apollo: Apollo) {
        this.listGql=`query aap_accountManagerService_list($filter: AccountFilter!,$orderBy: OrderBy){${accountManagerServiceQuery.accountManagerService_list}}`;
        this.totalCountGql=`query aap_accountManagerService_totalCount{${accountManagerServiceQuery.accountManagerService_totalCount}}`;
        this.searchGql=`query aap_accountManagerService_search($first: Int!,$offset: Float!,$filter: AccountFilter!,$orderBy: OrderBy){${accountManagerServiceQuery.accountManagerService_search}}`;
        this.searchObjectRef = apollo.watchQuery<AccountManagerService_searchResult>({ query: gql`${this.searchGql}`, fetchPolicy:'cache-first' });
        this.loadAllGql=`query aap_accountManagerService_loadAll{${accountManagerServiceQuery.accountManagerService_loadAll}}`;
        this.getByIdGql=`query aap_accountManagerService_getById($id: String!){${accountManagerServiceQuery.accountManagerService_getById}}`;
    }
    /**
     * 分页查询
     */
    list(variables: AccountManagerService_listVariables, options:AccountManagerServiceQueryOptions = { cachePolicy: 'no-cache', more: false }): Observable<ApolloQueryResult<AccountManagerService_listResult>> {
            return this.apollo.query({ query: gql`${this.listGql}`,variables ,fetchPolicy:options.cachePolicy});
    }
    /**
     * 统计库中所有对象的数据量
     */
    totalCount(options:AccountManagerServiceQueryOptions = { cachePolicy: 'no-cache', more: false }): Observable<ApolloQueryResult<AccountManagerService_totalCountResult>> {
            return this.apollo.query({ query: gql`${this.totalCountGql}`,fetchPolicy:options.cachePolicy});
    }
    /**
     * 游标查询
     */
    search(variables: AccountManagerService_searchVariables, options:AccountManagerServiceQueryOptions = { cachePolicy: 'cache-first', more: false }): Observable<ApolloQueryResult<AccountManagerService_searchResult>> {
        this.searchObjectRef.setVariables(variables);
        if(options.more){
            this.searchObjectRef.fetchMore({variables});
        }
        return this.searchObjectRef.valueChanges;
    }
    /**
     * 获取库中所有数据，数据量大时请谨慎使用
     */
    loadAll(options:AccountManagerServiceQueryOptions = { cachePolicy: 'cache-first', more: false }): Observable<ApolloQueryResult<AccountManagerService_loadAllResult>> {
            return this.apollo.query({ query: gql`${this.loadAllGql}`,fetchPolicy:options.cachePolicy});
    }
    /**
     * 获取一个对象
     */
    getById(variables: AccountManagerService_getByIdVariables, options:AccountManagerServiceQueryOptions = { cachePolicy: 'cache-first', more: false }): Observable<ApolloQueryResult<AccountManagerService_getByIdResult>> {
            return this.apollo.query({ query: gql`${this.getByIdGql}`,variables ,fetchPolicy:options.cachePolicy});
    }
    /**
     * 修改密码
     */
    modifyPassword(variables: AccountManagerService_modifyPasswordVariables): Observable<FetchResult<AccountManagerService_modifyPasswordResult>>{
        return this.apollo.mutate({mutation: gql`mutation aap_accountManagerService_modifyPassword($validPassword: String!,$password: String!){${accountManagerServiceMutation.accountManagerService_modifyPassword}}`, variables,fetchPolicy:'no-cache'});
    }
    /**
     * 保存对象
     */
    save(variables: AccountManagerService_saveVariables): Observable<FetchResult<AccountManagerService_saveResult>>{
        return this.apollo.mutate({mutation: gql`mutation aap_accountManagerService_save($entity: AccountInput!){${accountManagerServiceMutation.accountManagerService_save}}`, variables,fetchPolicy:'no-cache'});
    }
    /**
     * 删除一个对象
     */
    removeById(variables: AccountManagerService_removeByIdVariables): Observable<FetchResult<AccountManagerService_removeByIdResult>>{
        return this.apollo.mutate({mutation: gql`mutation aap_accountManagerService_removeById($id: String!){${accountManagerServiceMutation.accountManagerService_removeById}}`, variables,fetchPolicy:'no-cache'});
    }
    /**
     * 删除一批对象
     */
    removeByIdList(variables: AccountManagerService_removeByIdListVariables): Observable<FetchResult<AccountManagerService_removeByIdListResult>>{
        return this.apollo.mutate({mutation: gql`mutation aap_accountManagerService_removeByIdList($ids: [String]!){${accountManagerServiceMutation.accountManagerService_removeByIdList}}`, variables,fetchPolicy:'no-cache'});
    }









}
